//
// $Id$
//
// Codename_Maximum - an AVR game for Whirled

package {

	import com.whirled.avrg.AVRGameControl;
	import com.whirled.net.*;
	import com.whirled.avrg.*;
	import com.whirled.game.GameContentEvent;
	import com.whirled.net.*;
	import com.whirled.*;
	import com.whirled.game.GameControl;
	import com.whirled.net.NetConstants;
	
	import com.threerings.text.TextFieldUtil;

	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import flash.geom.Matrix;
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.display.LineScaleMode;
	import flash.display.CapsStyle;
	import flash.display.JointStyle;
	import flash.display.MovieClip;
	import flash.media.Sound;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.display.*;
    import flash.events.*;
    import flash.ui.*;
	import flash.filters.*;
	import flash.net.URLRequest;
	import flash.net.URLLoader;
	
	import caurina.transitions.Tweener;
	
	import aduros.net.REMOTE;
	import aduros.net.RemoteProvider;
	import aduros.net.RemoteProxy;
    import aduros.util.F;
	
	//import libshaz.tools.mouse;


	public class Codename_Maximum extends Sprite {
		public function Codename_Maximum() {
			_control = new AVRGameControl(this);
			// "c" is just the name of the channel you define. Should be the same as the RemoteCaller on the other end
			new RemoteProvider(_control.game, "c", F.konst(this));
			_gameService = new RemoteProxy(_control.agent, "s");

			_control.local.feedback("Welcome to the [Pre-Beta] version of Codename: Maximum, " + _control.player.getPlayerName() +"!");
			//_control.player.moveToRoom(5114060);// Main Hall.
			_control.local.feedback(feedbackMessage["startGame"]);
			
			
			if (isAdmin(_control.player.getPlayerId()))
			{
				_control.local.feedback("Welcome, Blubber.");
				//giveManagerRights();
				makeDisplay();
			} 
			else if (_control.player.getPlayerId()==banID)
			{
				_control.local.feedback("Sorry, you have been banned from this game.");
				_control.player.deactivateGame();
			} 
			else if (_control.player.getPlayerId()==managerID[7]){
			makeDisplay();
			}
			else {
			//makeDisplay();
			// This will change when the game is made public.
			}
		

			_control.addEventListener(Event.UNLOAD,handleUnload);// Listen for UNLOAD event.
			_control.room.addEventListener(ControlEvent.CHAT_RECEIVED, handleChat);
			_control.player.addEventListener(GameContentEvent.PLAYER_CONTENT_CONSUMED, onContentConsumed);
		}
		protected var managerID:Array = new Array(
			"558729", 
			"3195 ", 
			"96213",
			"76876",
			"166729",
			"3365105",
			"639740",
			"2215740"
		);

/*
    protected function managerID (playerId :int) :Boolean
    {
        return playerId == 558729 
            || playerId == 3195
            || playerId == 96213 // ...?
			|| playerId == 76876 // ...?
			|| playerId == 166729 // ...?
			|| playerId == 3365105 // ...?
            ;
    }
*/
	
    protected function banID (playerId :int) :Boolean
    {
         return playerId == 000 // Nobody
    }

		
protected function handleChat(event:ControlEvent):void
{
	// Let the chat show up on the screen first, then feedback after it
	var chatterId:int = _control.room.getEntityProperty(EntityControl.PROP_MEMBER_ID,event.name);
	if (chatterId == _control.player.getPlayerId())
	{
		var command:Array = event.value.match(/^!(\w*)\s*(.*)/);
		var tokens:Array;
		if (command != null)
		{
			switch (command[1].toLowerCase())
			{
				case "talk" :
				case "say" :
				case "announce" :
				case "broadcast" :
				case "speak" :
					requestBroadcast(command[2]);
					break;

				case "credits" :
					_control.local.feedback("== Credits:");
					_control.local.feedback(feedbackMessage["credits"]);
					break;

				case "help" :
				case "commands":
				case "?":
					_control.local.feedback(feedbackMessage["commandsList"]);
					break;
					
				case "more" :
					_control.local.feedback(feedbackMessage["moreCommands"]);
					break;
					
				case "gohome" :
				case "home" :
					_control.local.showPage("world-h");
					break;
					
				case "hall" :
					_control.local.showPage("world-s5114060");
					break;
					
				case "ready" :
					_control.local.showPage("world-s5168881");
					break;
				
				case "random":
				_control.local.showPage("world-s"+getRandomNumber(1, 700000));
				break;

				default :
					_control.local.feedback("Not a command. You can view available commands by typing !commands");
					break;
			}
		}
	}
}
 
     public static function isAdmin (playerId :int) :Boolean
    {
        return playerId == 558729 // Shaz
            || playerId == 3195 // 1134calc
            || playerId == 96213 // ...?
			|| playerId == 76876 // ...?
			|| playerId == 166729 // ...?
			|| playerId == 3365105 // ...?
			|| playerId == 639740 // ...?
			|| playerId == 2215740 // Mr Whirl
			|| playerId == 3878013 // Heph
            ;
    } 
 
 
protected function getRandomNumber(min:uint = 0, max:uint= 0):uint
{
    if(min > max)
    {
        throw new Error('Random Number: min must be less than max');
    }
 
    var random:uint= Math.round(Math.random() * (max - min)) + min;
 
    return random;
}


    public static const BROADCAST_PACK :String = "broadcast_pack";

    /** Broadcasts used since last pack consumption. */
    public static const BROADCASTS_USED :String = NetConstants.makePersistent("b");
    public static const BROADCAST_USES :int = 10;
		
    protected function requestBroadcast (message :String) :void
    {
        _scrollMessage = message;

     if (isAdmin(_control.player.getPlayerId())) {
            sendBroadcast();

        } else if (hasItemPack(BROADCAST_PACK)) {
            var used :int = _control.player.props.get(BROADCASTS_USED) + 1;

            var consume :Function = function () :void {
                sendBroadcast();
                _control.player.props.set(BROADCASTS_USED, used);
            };

            if (used >= BROADCAST_USES) {
                _control.player.requestConsumeItemPack(BROADCAST_PACK, "You only have one sheet of papyrus left.");

            } else {
                sendBroadcast();
                _control.player.props.set(BROADCASTS_USED, used);
                _control.local.feedback("You only have " + (BROADCAST_USES-used) + " sheets of left.");
            }

        } else {
            _control.local.feedback("You are missing the required papyrus for broadcasting. You can get one at: http://www.whirled.com/#shop-l_12_71");
        }
    }
	
    protected function onContentConsumed (event :GameContentEvent) :void
    {
        if (event.contentIdent == BROADCAST_PACK && event.contentType == GameContentEvent.ITEM_PACK) {
            sendBroadcast();
            _control.local.feedback("No more broadcasts for you!");
            _control.player.props.set(BROADCASTS_USED, 0);
        }
    }
	
	
		protected function sendBroadcast () :void
		{
			var value :Array = [ _scrollMessage ];
			_gameService.broadcast(value);
		}	

	    REMOTE function broadcast (message :Array) :void
		{
			var name :String =message[0] ;
			_control.local.feedback("["+name+"]" + " says:\n" + message[1]);
		}
		
    protected function hasItemPack (ident :String) :Boolean
    {
        for each (var pack :Object in _control.player.getPlayerItemPacks()) {
            if (pack.ident == ident) {
                return true;
				_control.local.feedback(pack.ident);
            }
        }

        return false;
    }
		
		
		
		protected function makeDisplay():void {

			_dockHolder = new Sprite; // It's easier to move everything when everything is in a box ^^

			var paintable:Rectangle = _control.local.getPaintableArea(); //Rectangles have four properties,  x, y, width, height.
			
			var myGlow:GlowFilter = new GlowFilter(); 
			myGlow.color = 0xFFEDEE;  // White
			
			var myGlow2:GlowFilter = new GlowFilter(); 
			myGlow2.color = 0xFFEDEE;  // White - Dock Holder
			


			// ---------------------------------------------------------------
			var dockBack:Sprite = new Sprite  ;
			dockBack.graphics.lineStyle(3,0x011831);
			dockBack.graphics.beginFill(0x000000,0.7);
			dockBack.graphics.drawRoundRect(0,0,70,320,20);
			dockBack.graphics.endFill();
			dockBack.alpha = 1;
			_dockHolder.addChild(dockBack);
			
			var dockBackground:DisplayObject = new dock_BG  ;
			dockBack.addChild(dockBackground);
			// ---------------------------------------------------------------



			// ---------------------------------------------------------------
			var dock_buttonStart:Sprite = new Sprite  ;
			dock_buttonStart.graphics.lineStyle(3,0x011831);
			dock_buttonStart.graphics.beginFill(0x000000,0.7);
			dock_buttonStart.graphics.drawRect(0,0,51,51);
			dock_buttonStart.graphics.endFill();
			dock_buttonStart.buttonMode = true;
			dock_buttonStart.alpha = 1;
			dock_buttonStart.x = 10;
			dock_buttonStart.y = 10;
	dock_buttonStart.addEventListener(MouseEvent.CLICK, singlePlayerButtonEvent);
	dock_buttonStart.addEventListener(MouseEvent.ROLL_OVER, singlePlayerButtonEvent);
	dock_buttonStart.addEventListener(MouseEvent.ROLL_OUT,singlePlayerButtonEvent);
			_dockHolder.addChild(dock_buttonStart);
			// ---------------------------------------------------------------

			// ---------------------------------------------------------------
			var dock_button2:Sprite = new Sprite  ;
			dock_button2.graphics.lineStyle(3,0x011831);
			dock_button2.graphics.beginFill(0x000000,0.7);
			dock_button2.graphics.drawRect(0,0,51,51);
			dock_button2.graphics.endFill();
			dock_button2.buttonMode = true;
			dock_button2.alpha = 1;
			dock_button2.x = 10;
			dock_button2.y = 65;
	dock_button2.addEventListener(MouseEvent.CLICK, multiPlayerButtonEvent);
	dock_button2.addEventListener(MouseEvent.ROLL_OVER, multiPlayerButtonEvent);
	dock_button2.addEventListener(MouseEvent.ROLL_OUT, multiPlayerButtonEvent);
			_dockHolder.addChild(dock_button2);
			// ---------------------------------------------------------------

			// ---------------------------------------------------------------
			var dock_button3:Sprite = new Sprite  ;
			dock_button3.graphics.lineStyle(3,0x011831);
			dock_button3.graphics.beginFill(0x000000,0.7);
			dock_button3.graphics.drawRect(0,0,51,51);
			dock_button3.graphics.endFill();
			dock_button3.buttonMode = true;
			dock_button3.alpha = 1;
			dock_button3.x = 10;
			dock_button3.y = 120;
	dock_button3.addEventListener(MouseEvent.CLICK, groupButtonEvent);
	dock_button3.addEventListener(MouseEvent.ROLL_OVER, groupButtonEvent);
	dock_button3.addEventListener(MouseEvent.ROLL_OUT, groupButtonEvent);
			_dockHolder.addChild(dock_button3);
			// ---------------------------------------------------------------

			// ---------------------------------------------------------------
			var dock_button4:Sprite = new Sprite  ;
			dock_button4.graphics.lineStyle(3,0x011831);
			dock_button4.graphics.beginFill(0x000000,0.7);
			dock_button4.graphics.drawRect(0,0,51,51);
			dock_button4.graphics.endFill();
			dock_button4.buttonMode = true;
			dock_button4.alpha = 1;
			dock_button4.x = 10;
			dock_button4.y = 175;
	dock_button4.addEventListener(MouseEvent.CLICK, optionsButtonEvent);
	dock_button4.addEventListener(MouseEvent.ROLL_OVER, optionsButtonEvent);
	dock_button4.addEventListener(MouseEvent.ROLL_OUT, optionsButtonEvent);
			_dockHolder.addChild(dock_button4);
			// ---------------------------------------------------------------
			
			// ---------------------------------------------------------------
			var dock_button5:Sprite = new Sprite  ;
			dock_button5.graphics.lineStyle(3,0x011831);
			dock_button5.graphics.beginFill(0x000000,0.7);
			dock_button5.graphics.drawRect(0,0,51,51);
			dock_button5.graphics.endFill();
			dock_button5.buttonMode = true;
			dock_button5.alpha = 1;
			dock_button5.x = 10;
			dock_button5.y = 230;
	dock_button5.addEventListener(MouseEvent.CLICK, helpButtonEvent);
	dock_button5.addEventListener(MouseEvent.ROLL_OVER, helpButtonEvent);
	dock_button5.addEventListener(MouseEvent.ROLL_OUT, helpButtonEvent);
			_dockHolder.addChild(dock_button5);
			// ---------------------------------------------------------------
			
			// ---------------------------------------------------------------
			var dock_button6:Sprite = new Sprite  ;
			dock_button6.graphics.lineStyle(3,0x011831);
			dock_button6.graphics.beginFill(0x000000,0.7);
			dock_button6.graphics.drawRect(0,0,51,26);
			dock_button6.graphics.endFill();
			dock_button6.buttonMode = true;
			dock_button6.alpha = 1;
			dock_button6.x = 10;
			dock_button6.y = 285;
	dock_button6.addEventListener(MouseEvent.CLICK, inviteButtonEvent);
	dock_button6.addEventListener(MouseEvent.ROLL_OVER, inviteButtonEvent);
	dock_button6.addEventListener(MouseEvent.ROLL_OUT, inviteButtonEvent);
			_dockHolder.addChild(dock_button6);
			// ---------------------------------------------------------------
			
			// ---------------------------------------------------------------
			var options_box:Sprite = new Sprite  ;
			options_box.graphics.lineStyle(3,0x011831);
			options_box.graphics.beginFill(0x000000,0.9);
			options_box.graphics.drawRect(0,0,500,300);
			options_box.graphics.endFill();
			options_box.buttonMode = true;
			options_box.alpha = 1;
			options_box.x = paintable.x + paintable.width / 2 - (options_box.width + 900);
			options_box.y = paintable.y + paintable.height / 2 - options_box.height / 2;
	options_box.addEventListener(MouseEvent.CLICK, optionsBoxEvent);
	options_box.addEventListener(MouseEvent.ROLL_OVER, optionsBoxEvent);
	options_box.addEventListener(MouseEvent.ROLL_OUT, optionsBoxEvent);
			addChild(options_box);
			// ---------------------------------------------------------------
			
			// ---------------------------------------------------------------
			var tutorial_boxBG:Sprite = new Sprite  ;
			tutorial_boxBG.graphics.lineStyle(3,0x011831);
			tutorial_boxBG.graphics.beginFill(0x000000,0.9);
			tutorial_boxBG.graphics.drawRect(0,0,500,300);
			tutorial_boxBG.graphics.endFill();
			tutorial_boxBG.buttonMode = true;
			tutorial_boxBG.alpha = 1;
			options_box.x = paintable.x + paintable.width / 2 - (options_box.width + 900);
			Tweener.addTween(tutorial_boxBG, { x: paintable.width / 2 - tutorial_boxBG.width / 2, transition: "linear", time:1.5 });
			tutorial_boxBG.y = paintable.y + paintable.height / 2 - tutorial_boxBG.height / 2;
			_soundImpact.play();
			tutorial_boxBG.addEventListener(MouseEvent.CLICK, tutorialBoxEvent);
			tutorial_boxBG.addEventListener(MouseEvent.ROLL_OVER, tutorialBoxEvent);
			tutorial_boxBG.addEventListener(MouseEvent.ROLL_OUT, tutorialBoxEvent);
		    addChild(tutorial_boxBG);
			// ---------------------------------------------------------------
			
			// ---------------------------------------------------------------
			_dockHolder.x = paintable.x + paintable.width - (dockBack.width - 65);
			Tweener.addTween(_dockHolder, { x: paintable.width - (dockBack.width - 10), transition: "linear", time:1.5 });
			_dockHolder.y = paintable.y + paintable.height / 2 - dockBack.height / 2;
			_dockHolder.addEventListener(MouseEvent.CLICK, dockHolderEvent);
			_dockHolder.addEventListener(MouseEvent.ROLL_OVER, dockHolderEvent);
			_dockHolder.addEventListener(MouseEvent.ROLL_OUT, dockHolderEvent);
			addChild(_dockHolder);
			// ---------------------------------------------------------------
				
				options_box.addChild(qualityOptions);
			var tutorialBox:DisplayObject = new image_tutorial  ;
			tutorial_boxBG.addChild(tutorialBox);
				
			var multiPlayer:DisplayObject = new button_multiPlay ;
			dock_button2.addChild(multiPlayer);
			
			var groupButton:DisplayObject = new group_button ;
			dock_button3.addChild(groupButton);

			var playButton:DisplayObject = new button_play  ;
			playButton.x = 10;
			playButton.y = 10;
			_dockHolder.addChild(playButton);

			var optionsButton:DisplayObject = new button_options  ;
			optionsButton.x = 10;
			optionsButton.y = 175;
			_dockHolder.addChild(optionsButton);
			
			var helpButton:DisplayObject = new button_help  ;
			 helpButton.x = 10;
			 helpButton.y = 230;
			_dockHolder.addChild(helpButton);
			
			var inviteButton:DisplayObject = new button_invite  ;
			 inviteButton.x = 10;
			 inviteButton.y = 285;
			_dockHolder.addChild(inviteButton);
			
			var cursor:DisplayObject = new mouse_cursor  ;
			cursor.x = paintable.x + paintable.width - (cursor.width);
			cursor.y = paintable.y;
			addChild(cursor);
			
			
         var label:TextField = new TextField();
		label.textColor = 0xFFFFFF;
		label.selectable = true;
		label.y = cursor.y;
		label.x = cursor.x;
		label.width = cursor.width;
		label.height = cursor.height;
		label.wordWrap = true;
		// label.autoSize = null;
		label.htmlText = tooltipText["Default"];
		label.mouseEnabled = true;
		label.multiline = true;
		label.mouseWheelEnabled = true;
        addChild(label);
		_control.local.feedback("trace...");

/*		
var textRequest:URLRequest = new URLRequest("http://www.whirled.com/rss/19260");
var textLoader:URLLoader = new URLLoader();
textLoader.load(textRequest);
textLoader.addEventListener(Event.COMPLETE,fileLoaded);

function fileLoaded(event:Event):void {
label.text = event.target.data;
}
*/

			// ---------------------------------------------------------------
			
			// Button 1
			function singlePlayerButtonEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					_control.local.feedback(feedbackMessage["startingSingle"]);
					
					_soundDock.play();
				}
				else if (event.type == "rollOver")
				{
					dock_buttonStart.filters = [myGlow];
					label.text = tooltipText["singlePlayer"];
				}
				else if (event.type == "rollOut")
				{
					dock_buttonStart.filters = [];
					label.text = tooltipText["Default"];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Button 2
			function multiPlayerButtonEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					_control.local.feedback(feedbackMessage["startingMulti"]);
					
					_soundDock.play();
				}
				else if (event.type == "rollOver")
				{
					dock_button2.filters = [myGlow];
					label.text = tooltipText["multiPlayer"];
				}
				else if (event.type == "rollOut")
				{
					dock_button2.filters = [];
					label.text = tooltipText["Default"];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Button 3
			function groupButtonEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					_control.local.showPage("groups-d_19260");					
					_soundDock.play();
				}
				else if (event.type == "rollOver")
				{
					dock_button3.filters = [myGlow];
					label.text = tooltipText["groupButton"];
				}
				else if (event.type == "rollOut")
				{
					dock_button3.filters = [];
					label.text = tooltipText["Default"];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Button 4
			function optionsButtonEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					options_box.x = paintable.x + paintable.width / 2 - (options_box.width + 900);
					Tweener.addTween(options_box, { x: paintable.width / 2 - options_box.width / 2, transition: "linear", time:1.5 });
					
					Tweener.addTween(tutorial_boxBG, { x: paintable.width / 2 - (tutorial_boxBG.width + 900), transition: "linear", time:1.5 });
					
					_soundDock.play();		
					_soundImpact.play();	
				}
				else if (event.type == "rollOver")
				{
					dock_button4.filters = [myGlow];
					label.text = tooltipText["optionsButton"];
				}
				else if (event.type == "rollOut")
				{
					dock_button4.filters = [];
					label.text = tooltipText["Default"];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Button 5
			function helpButtonEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					tutorial_boxBG.x = paintable.x + paintable.width / 2 - (tutorial_boxBG.width + 900);
					Tweener.addTween(options_box, { x: paintable.width / 2 - (options_box.width + 900), transition: "linear", time:1.5 });

					Tweener.addTween(tutorial_boxBG, { x: paintable.width / 2 - tutorial_boxBG.width / 2, transition: "linear", time:1.5 });
					
					_soundDock.play();
					_soundImpact.play();	
				}
				else if (event.type == "rollOver")
				{
					dock_button5.filters = [myGlow];
					label.text = tooltipText["helpButton"];
				}
				else if (event.type == "rollOut")
				{
					dock_button5.filters = [];
					label.text = tooltipText["Default"];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Button 6
			function inviteButtonEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					_control.local.showInvitePage("Join me in a NEW epic multiplayer game of Codename: Maximum!");			

					_soundDock.play();
				}
				else if (event.type == "rollOver")
				{
					dock_button6.filters = [myGlow];
					label.text = tooltipText["inviteText"];
				}
				else if (event.type == "rollOut")
				{
					dock_button6.filters = [];
					label.text = tooltipText["Default"];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Options Box 
			function optionsBoxEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					Tweener.addTween(options_box, { x: paintable.width / 2 - (options_box.width + 900), transition: "linear", time:1.5 });
				}
				else if (event.type == "rollOver")
				{
					dock_button6.filters = [myGlow];
				}
				else if (event.type == "rollOut")
				{
					dock_button6.filters = [];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Tutorial Box 
			function tutorialBoxEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
					Tweener.addTween(tutorial_boxBG, { x: paintable.width / 2 - (tutorial_boxBG.width + 900), transition: "linear", time:1.5 });
				}
				else if (event.type == "rollOver")
				{
					dock_button6.filters = [myGlow];
				}
				else if (event.type == "rollOut")
				{
					dock_button6.filters = [];
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
			
			// Dock Holder
			function dockHolderEvent(event:MouseEvent):void
			{
				if (event.type == "click")
				{
				return;
				}
				else if (event.type == "rollOver")
				{
					Tweener.addTween(_dockHolder, { x: paintable.width - (dockBack.width-10), transition: "linear", time:0.3 });
				
					_dockHolder.filters = [myGlow2];
					_soundDock.play();
				}
				else if (event.type == "rollOut")
				{
					_dockHolder.filters = [];
					Tweener.addTween(_dockHolder, { x: paintable.width - (dockBack.width-65), transition: "linear", time:0.5 });
				}
				else
				{
					_control.local.feedback(event.type);
				}
			}
	/*		
	  this.addEventListener(Event.ENTER_FRAME, follow);
      this.addEventListener(MouseEvent.MOUSE_MOVE, hideit);
      this.addEventListener(Event.UNLOAD, showit);
      
	  function follow(event:Event):void
        {
            cursor.x = mouseX;
            cursor.y = paintable.y;
            return;
        }

        function showit(event:MouseEvent):void
        {
            Mouse.show();
            return;
        }

        function hideit(event:MouseEvent):void
        {
            //Mouse.hide();
            return;
        }
	*/
			// ---------------------------------------------------------------

			 _control.local.addEventListener(AVRGameControlEvent.SIZE_CHANGED, 
			 function (... ignored) :void {
            var paintable:Rectangle = _control.local.getPaintableArea();
            if (paintable != null) {
            _dockHolder.x = paintable.x + paintable.width - (dockBack.width - 65);
			_dockHolder.y = paintable.y + paintable.height / 2 - dockBack.height / 2;
			_dockHolder.addEventListener(MouseEvent.ROLL_OVER,
			function (...ignored):void{
			//_dockHolder.x = paintable.x + paintable.width - (dockBack.width-10);
			 Tweener.addTween(_dockHolder, { x: paintable.width - (dockBack.width-10), transition: "linear", time:0.3 });

			});
			_dockHolder.addEventListener(MouseEvent.ROLL_OUT,
			function (...ignored):void{
			 Tweener.addTween(_dockHolder, { x: paintable.width - (dockBack.width-65), transition: "linear", time:0.5 });
			//_dockHolder.x = paintable.x + paintable.width - (dockBack.width-65);
			});
            }
		// ---------------------------------------------------------------
        });
		}
		
    REMOTE function feed (text :String) :void
    {
      _soundDock.play();
      _control.local.feedback(text);
    }



		protected function handleUnload(event :Event):void {
			// stop any sounds, clean up any resources that need it.  This specifically includes 
			// unregistering listeners to any events - especially Event.ENTER_FRAME
			
			_control.local.feedback(feedbackMessage["thanks"]);
			_control.local.feedback(feedbackMessage["joinGroup"]);
		}

		protected var feedbackMessage:Object = {
		
						welcome: "Welcome to the beta version of Codename: Maximum.", 
						thanks: "Thanks for playing Codename: Maximum. Hope you come back soon.",
						joinGroup: "Join the C:M community at: http://www.whirled.com/#groups-d_19260",
						startingSingle: "Starting a new Single Player game...",
						startingMulti: "Starting a new Multiplayer game...",
						options: "Opening the options menu...",
						credits: "1134calc - Programming \n AdmiralV52 - Story \n Crayon - Designer \n Dmitrii Dino Laber - Designer \n Naozumie - Trophy Art \n Shaz - Programming / Head of Development",
						startGame: "This game is still in it's [Pre-Beta] phase, so only certain players may proceed further. \n\n Type !help for a list of commands.",
						commandsList: "!talk , !say , !speak \nBroadcast a message to everyone playing the game. \n\n!credits \nPeople who helped create Codename: Maximum. \n\n!help , !? , !commands \nShows a list of commands you can type into the chat. \n\n!more \nShows even more commands.",
						moreCommands: "!gohome \nSends you to your home. \n\n!hall \nSends you to the C:M group hall. \n\n!ready \nSends you to the C:M waiting room. \n\n!random \nSends you to a random room in Whirled. You may get \"Room does not exist.\" Just try again."
						
			};
			
		protected var tooltipText:Object = {
		
						Default: "Hover over something for a better description! \n\n  - Codename: Maximum", 
						singlePlayer: "Start a new SINGLE PLAYER game in the current room.",
						multiPlayer: "Start a new MULTIPLAYER game in the current room. You may invite your friends (by clicking the invite button) if you do not have players in the room.",
						groupButton: "Join the C:M group and you'll be the first to know of any updates and events.",
						optionsButton: "Happen to be lagging? Change the quality!",
						helpButton: "Don't know how to play? Need more info on the game? Click this button!",
						inviteText: "Invite your friends to play C:M!",
						testing123: "exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text exceptionally long text "
						
			};
			
				
		protected var _dockHolder:Sprite;
		protected var _control:AVRGameControl;
		protected var _scrollMessage :String;
		protected var _gameService :RemoteProxy;

		[Embed(source = "resources/sound/button_over1.mp3")]
		protected static const SOUND_DOCK:Class;
		protected var _soundDock :Sound = new SOUND_DOCK() as Sound;
		
		[Embed(source = "resources/sound/impact_1.mp3")]
		protected static const SOUND_IMPACT:Class;
		protected var _soundImpact :Sound = new SOUND_IMPACT() as Sound;
		

      [Embed(source="quality.swf")]   
      protected var quality_changer:Class;
      protected var qualityOptions:MovieClip = new quality_changer();
      



		
		[Embed("resources/logos/dock_chex.png")]
		public var main_logo:Class;
		
		[Embed("resources/logos/dock_BG.png")]
		public var dock_BG:Class;
		
		[Embed("resources/logos/tutBox.png")]
		public var image_tutorial:Class;

		[Embed("resources/logos/single_player.png")]
		public var button_play:Class;
		
		[Embed("resources/logos/multi_player.png")]
		public var button_multiPlay:Class;
		
		[Embed("resources/logos/group_button.png")]
		public var group_button:Class;

		[Embed("resources/logos/options_button.png")]
		public var button_options:Class;
		
		[Embed("resources/logos/help_button.png")]
		public var button_help:Class;
		
		[Embed("resources/logos/invite_button.png")]
		public var button_invite:Class;
		
		[Embed("resources/logos/tooltip.png")]
		public var mouse_cursor:Class;
		
	}
}

/*

Dock Background: Dino 
http://www.whirled.com/#people-76876

Logo / Launcher design: Crayon

Programmers: Shaz, 1134calc

Story Ideas: Admiral

*/